﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Library;

namespace QLKH.PopUp.vattu
{
    public partial class popSuaLoaiDH : Form
    {
        private Int16 ldhid = -1;
        public popSuaLoaiDH(Int16 id)
        {
            InitializeComponent();
            ldhid = id;
        }

        private void btquit_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void popSuaLoaiDH_Load(object sender, EventArgs e)
        {
            clLoaiDH ldh = new clLoaiDH();
            DataTable dtloaidh = ldh.loaidh_chitiet(ldhid);
            if (dtloaidh != null && dtloaidh.Rows.Count > 0)
            {
                txttenloaidh.Text = dtloaidh.Rows[0]["ten"].ToString();
                txtghichu.Text = dtloaidh.Rows[0]["ghichu"].ToString();
            }
        }

        public delegate void SuaLDH(int outid);
        // khai báo 1 kiểu hàm delegate
        public SuaLDH MyFunction;

        private void btsave_Click(object sender, EventArgs e)
        {
            if (MyFunction != null)
            {// tại đây gọi nó
                string ten = txttenloaidh.Text.Trim();
                string ghichu = txtghichu.Text.Trim();

                clLoaiDH ldh = new clLoaiDH();
                int outid = ldh.edit_loaidh(ldhid, ten, ghichu);
                MyFunction(outid);
            }
            this.Close();
        }

    }
}
